<!DOCTYPE html>
<html lang="en">
<head><!-- hexo injector head_begin start -->
        <link rel="preconnect" href="https://blog.fantasyke.cn/picx-images-hosting" crossorigin=""><!-- hexo injector head_begin end -->
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/uploads/avatar.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/uploads/avatar.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="google-site-verification" content="0qBBGdG7vYORyT5XLZRUqQZ_y5kKYhgyUwNqjSIImg0">
  <meta name="msvalidate.01" content="63C90D0EC3DA6C31FD109132B7BEF502">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Zen+Maru+Gothic:300,300italic,400,400italic,700,700italic%7CZCOOL+XiaoWei:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha256-5eIC48iZUHmSlSUz9XtjRyK2mzQkHScZY1WdMaoz74E=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.31/fancybox/fancybox.css" integrity="sha256-gkQVf8UKZgQ0HyuxL/VnacadJ+D2Kox2TCEBuNQg5+w=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"blog.fantasyke.cn","root":"/","images":"/images","scheme":"Mist","darkmode":false,"version":"8.21.1","exturl":true,"sidebar":{"position":"right","width_expanded":350,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"copycode":{"enable":true,"style":null},"fold":{"enable":true,"height":500},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"gitalk","storage":true,"lazyload":true,"nav":{"gitalk":{"text":"gitalk","order":-1}},"activeClass":"gitalk"},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"},"path":"/search.xml","localsearch":{"enable":true,"top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="💡 Dockerfile 是用来构建 Docker 镜像的文件，可以理解为命令参数脚本">
<meta property="og:type" content="article">
<meta property="og:title" content="5.Dockerfile">
<meta property="og:url" content="https://blog.fantasyke.cn/posts/11767/index.html">
<meta property="og:site_name" content="Fantasy&#39;Ke Blog">
<meta property="og:description" content="💡 Dockerfile 是用来构建 Docker 镜像的文件，可以理解为命令参数脚本">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.5q7fvep4ep.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.58he6tnxat.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.6pnj8kse8h.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.2a543bg8jo.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.4n7qkiudta.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1e8mnv72b7.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1026wzyzzk.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.4ckwrdfs71.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.361lirri0b.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1hs8ll1dsv.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1hs8ll1lhc.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.2a543big37.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.45phjre6c.webp">
<meta property="og:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.9kg7edawsp.webp">
<meta property="article:published_time" content="2023-04-11T01:44:02.000Z">
<meta property="article:modified_time" content="2024-12-17T06:36:35.378Z">
<meta property="article:author" content="Fantasy-ke">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fantasy-ke.github.io/picx-images-hosting/docker/image.5q7fvep4ep.webp">


<link rel="canonical" href="https://blog.fantasyke.cn/posts/11767/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"en","comments":true,"permalink":"https://blog.fantasyke.cn/posts/11767/","path":"posts/11767/","title":"5.Dockerfile"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>5.Dockerfile | Fantasy'Ke Blog</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="Fantasy'Ke Blog" type="application/atom+xml">
<style>.darkmode--activated{--body-bg-color:#282828;--content-bg-color:#333;--card-bg-color:#555;--text-color:#ccc;--blockquote-color:#bbb;--link-color:#ccc;--link-hover-color:#eee;--brand-color:#ddd;--brand-hover-color:#ddd;--table-row-odd-bg-color:#282828;--table-row-hover-bg-color:#363636;--menu-item-bg-color:#555;--btn-default-bg:#222;--btn-default-color:#ccc;--btn-default-border-color:#555;--btn-default-hover-bg:#666;--btn-default-hover-color:#ccc;--btn-default-hover-border-color:#666;--highlight-background:#282b2e;--highlight-foreground:#a9b7c6;--highlight-gutter-background:#34393d;--highlight-gutter-foreground:#9ca9b6}.darkmode--activated img{opacity:.75}.darkmode--activated img:hover{opacity:.9}.darkmode--activated code{color:#69dbdc;background:0 0}button.darkmode-toggle{z-index:9999}.darkmode-ignore,img{display:flex!important}.beian img{display:inline-block!important}</style></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Fantasy'Ke Blog</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="Search" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>About</a></li><li class="menu-item menu-item-photos"><a href="/photos/" rel="section"><i class="fas fa-camera-retro fa-fw"></i>photos</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>Search
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="Searching..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#dockerfile"><span class="nav-number">1.</span> <span class="nav-text"> Dockerfile</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#dockerfile-2"><span class="nav-number">2.</span> <span class="nav-text"> Dockerfile</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%AE%80%E4%BB%8B"><span class="nav-number">2.1.</span> <span class="nav-text"> 简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%91%BD%E4%BB%A4"><span class="nav-number">2.2.</span> <span class="nav-text"> 命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9E%84%E5%BB%BA%E9%95%9C%E5%83%8F"><span class="nav-number">2.3.</span> <span class="nav-text"> 构建镜像</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-build"><span class="nav-number">2.3.1.</span> <span class="nav-text"> docker build</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E6%9E%84%E5%BB%BA%E8%AE%B0%E5%BD%95"><span class="nav-number">2.4.</span> <span class="nav-text"> 查看构建记录</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-history"><span class="nav-number">2.4.1.</span> <span class="nav-text"> docker history</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#cmd-%E4%B8%8E-entrypoint-%E5%8C%BA%E5%88%AB"><span class="nav-number">2.5.</span> <span class="nav-text"> CMD 与 ENTRYPOINT 区别</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#cmd-%E5%91%BD%E4%BB%A4%E6%BC%94%E7%A4%BA"><span class="nav-number">2.5.1.</span> <span class="nav-text"> CMD 命令演示</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#entrypoint-%E5%91%BD%E4%BB%A4%E6%BC%94%E7%A4%BA"><span class="nav-number">2.5.2.</span> <span class="nav-text"> ENTRYPOINT 命令演示</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%9E%E6%88%98"><span class="nav-number">2.6.</span> <span class="nav-text"> 实战</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%8C%85%E5%90%ABvim%E5%91%BD%E4%BB%A4%E7%9A%84centos%E9%95%9C%E5%83%8F"><span class="nav-number">2.6.1.</span> <span class="nav-text"> 创建包含vim命令的centos镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89tomcat%E7%8E%AF%E5%A2%83%E9%95%9C%E5%83%8F"><span class="nav-number">2.6.2.</span> <span class="nav-text"> 自定义tomcat环境镜像</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%91%E5%B8%83%E9%95%9C%E5%83%8F%E5%88%B0-docker-hub"><span class="nav-number">2.7.</span> <span class="nav-text"> 发布镜像到 Docker Hub</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%91%E5%B8%83%E9%95%9C%E5%83%8F"><span class="nav-number">2.7.1.</span> <span class="nav-text"> 发布镜像</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-push"><span class="nav-number">2.7.2.</span> <span class="nav-text"> docker push</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8C%87%E5%AE%9A%E9%95%9C%E5%83%8F%E6%A0%87%E7%AD%BE"><span class="nav-number">2.7.3.</span> <span class="nav-text"> 指定镜像标签</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-tag"><span class="nav-number">2.7.4.</span> <span class="nav-text"> docker tag</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E5%9B%BD%E5%86%85%E9%95%9C%E5%83%8F%E7%AB%99"><span class="nav-number">2.8.</span> <span class="nav-text"> 配置国内镜像站</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%91%E5%B8%83%E9%95%9C%E5%83%8F%E5%88%B0%E9%98%BF%E9%87%8C%E4%BA%91%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93"><span class="nav-number">2.9.</span> <span class="nav-text"> 发布镜像到阿里云镜像仓库</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Fantasy-ke"
      src="/uploads/avatar.png">
  <p class="site-author-name" itemprop="name">Fantasy-ke</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">36</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">32</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2ZhbnRhc3kta2U=" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;fantasy-ke"><i class="fab fa-github fa-fw"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly94LmNvbS9BX0RyZWFtZXJfSGFyZA==" title="Twitter → https:&#x2F;&#x2F;x.com&#x2F;A_Dreamer_Hard"><i class="fab fa-twitter fa-fw"></i>Twitter</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly93d3cueW91dHViZS5jb20vQCVFNSU5MSVBOCVFNiVBMiVBNi16OWk=" title="YouTube → https:&#x2F;&#x2F;www.youtube.com&#x2F;@%E5%91%A8%E6%A2%A6-z9i"><i class="fab fa-youtube fa-fw"></i>YouTube</span>
      </span>
  </div>
<div class="cc-license animated" itemprop="sponsor">
  <a href="https://www.netlify.com" class="cc-opacity" title="Deploy with Netlify → https://www.netlify.com" target="_blank"><img width="80" src="https://www.netlify.com/img/global/badges/netlify-dark.svg" alt="Netlify"></a>
</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.css">
<div id="aplayer" style="position:relative;left;0;bottom:0;"></div>
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/color-thief-don@2.0.2/src/color-thief.js"></script>
<script>
  const ap = new APlayer({
    container: document.getElementById('aplayer'),
    autoplay: false, //自动播放
    listFolded: true, //播放列表默认折叠
    listMaxHeight: 90, //播放列表最大高度
    order: 'list', //音频循环顺序, 可选值: 'list', 'random'
    loop: 'all', //音频循环播放, 可选值: 'all', 'one', 'none'
    theme: '#e9e9e9', //切换音频时的主题色，优先级低于audio.theme
    preload: 'none', //音频预加载，可选值: 'none', 'metadata', 'auto'
    mutex: true, //互斥，阻止多个播放器同时播放，当前播放器播放时暂停其他播放器
    lrcType: 3, //歌词格式，可选值：3（LRC文件歌词格式），1（JS字符串歌词格式）
    volume: 0.7, //默认音量，请注意播放器会记忆用户设置，用户手动设置音量后默认音量即失效
    fixed: false, //吸底模式（fixed:true），迷你模式（mini:true），普通模式（注释此行或者设置fixed:false）
    audio: [{
        name: '平凡之路',
        artist: '朴树',
        lrc: '/downloads/lrc/平凡之路-朴树.lrc',
        cover: 'http://p2.music.126.net/W_5XiCv3rGS1-J7EXpHSCQ==/18885211718782327.jpg?param=300x300',
        url: 'http://ws.stream.qqmusic.qq.com/C4000007nRJ74eQsF6.m4a?guid=942726817&vkey=64755357C5716983BEECE2981FEC3954F0DD03E7630EFF769D9C40C31F50D53E7D260CB63E22CE8F954B1144083716A1BABFC2093F8F1C14&uin=&fromtag=120032'
      },
      {
        name: '后会无期',
        artist: '徐良,汪苏泷',
        lrc: '/downloads/lrc/后会无期-G.E.M.邓紫棋.lrc',
        cover: 'http://p1.music.126.net/vpvPajo3kn88nHc7jUjeWQ==/5974746185758035.jpg?param=300x300',
        url: 'http://ws.stream.qqmusic.qq.com/C400004ECnYg0QNchK.m4a?guid=893251117&vkey=D9DCBB8C4A4CAF8550E97A2A574DE1231DFDD8BC0989CC724742C7B9831C4108E0A805A46E0F2B2A556228467C146B9C312E3E8B498614C7&uin=&fromtag=120032'
      }
    ]
  });

  // 实现切换音频时，根据音频的封面图片自适应主题色
  const colorThief = new ColorThief();
  const setTheme = (index) => {
    if (!ap.list.audios[index].theme) {
      colorThief.getColorAsync(ap.list.audios[index].cover, function(color) {
        ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
      });
    }
  };
  setTheme(ap.list.index);
  ap.on('listswitch', (data) => {
    setTheme(data.index);
  });
</script>



        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          Links
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9mYW50YXN5LWtlLmdpdGh1Yi5pbw==" title="https:&#x2F;&#x2F;fantasy-ke.github.io">SunBlog</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9mYW50YXN5LWtlLmdpdGh1Yi5pbw==" title="https:&#x2F;&#x2F;fantasy-ke.github.io">做梦的努力者</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL0ZhbnRhc3ktS2U=" title="https:&#x2F;&#x2F;github.com&#x2F;Fantasy-Ke">github</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9naXRlZS5jb20vZmFudGFzeV9rZQ==" title="https:&#x2F;&#x2F;gitee.com&#x2F;fantasy_ke">gitee</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vZmFudGFzeS1rZQ==" title="https:&#x2F;&#x2F;www.cnblogs.com&#x2F;fantasy-ke">我的园子</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9hYnAuaW8v" title="https:&#x2F;&#x2F;abp.io&#x2F;">abp</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9hYnAuaW8vZG9jcy9sYXRlc3Qv" title="https:&#x2F;&#x2F;abp.io&#x2F;docs&#x2F;latest&#x2F;">abp doc</span>
            </li>
            <li class="links-of-blogroll-item">
              <span class="exturl" data-url="aHR0cHM6Ly9ibG9ncy5tYXNhc3RhY2suY29tLw==" title="https:&#x2F;&#x2F;blogs.masastack.com&#x2F;">masa blog</span>
            </li>
        </ul>
      </div>
    </div>
        <div class="pjax">
        <div class="sidebar-inner sidebar-post-related">
          <div class="animated">
              <div class="links-of-blogroll-title"><i class="fa fa-signs-post fa-fw"></i>
    Related Posts
  </div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/posts/61442/" rel="bookmark">
        <time class="popular-posts-time">2023-04-11</time>
        <br>
      7.Docker Compose
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/posts/53249/" rel="bookmark">
        <time class="popular-posts-time">2023-04-11</time>
        <br>
      1.Docker介绍
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/posts/14184/" rel="bookmark">
        <time class="popular-posts-time">2023-04-11</time>
        <br>
      2.Docker基本使用
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/posts/31784/" rel="bookmark">
        <time class="popular-posts-time">2023-04-11</time>
        <br>
      3.Docker基本命令
      </a>
    </li>
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/posts/23547/" rel="bookmark">
        <time class="popular-posts-time">2023-04-11</time>
        <br>
      4.Docker镜像原理
      </a>
    </li>
  </ul>

          </div>
        </div>
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="en">
    <link itemprop="mainEntityOfPage" href="https://blog.fantasyke.cn/posts/11767/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/uploads/avatar.png">
      <meta itemprop="name" content="Fantasy-ke">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Fantasy'Ke Blog">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="5.Dockerfile | Fantasy'Ke Blog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          5.Dockerfile
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2023-04-11 09:44:02" itemprop="dateCreated datePublished" datetime="2023-04-11T09:44:02+08:00">2023-04-11</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2024-12-17 14:36:35" itemprop="dateModified" datetime="2024-12-17T14:36:35+08:00">2024-12-17</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/DevOps/" itemprop="url" rel="index"><span itemprop="name">DevOps</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="Views" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">Views: </span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="Word count in article">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">Word count in article: </span>
      <span>4.7k</span>
    </span>
    <span class="post-meta-item" title="Reading time">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">Reading time &asymp;</span>
      <span>17 mins.</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h1 id="dockerfile"><a class="markdownIt-Anchor" href="#dockerfile"></a> Dockerfile</h1>
<h1 id="dockerfile-2"><a class="markdownIt-Anchor" href="#dockerfile-2"></a> Dockerfile</h1>
<h2 id="简介"><a class="markdownIt-Anchor" href="#简介"></a> 简介</h2>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.5q7fvep4ep.webp" alt="image.png" /></p>
<p>Dockerfile 是用来构建 Docker 镜像的文件，可以理解为<strong>命令参数脚本</strong>。</p>
<p>Dockerfile 是面向开发的，想要打包项目，就要编写 Dockerfile 文件。</p>
<h2 id="命令"><a class="markdownIt-Anchor" href="#命令"></a> 命令</h2>
<p>以上面的 centos 官方镜像的 Dockerfile 为例。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">FROM scratch</span><br><span class="line">ADD centos<span class="literal">-7-docker</span>.tar.xz /</span><br><span class="line">LABEL org.label<span class="literal">-schema</span>.schema<span class="literal">-version</span>=<span class="string">&quot;1.0&quot;</span> \</span><br><span class="line">    org.label<span class="literal">-schema</span>.name=<span class="string">&quot;CentOS Base Image&quot;</span> \</span><br><span class="line">    org.label<span class="literal">-schema</span>.vendor=<span class="string">&quot;CentOS&quot;</span> \</span><br><span class="line">    org.label<span class="literal">-schema</span>.license=<span class="string">&quot;GPLv2&quot;</span> \</span><br><span class="line">    org.label<span class="literal">-schema</span>.<span class="built_in">build-date</span>=<span class="string">&quot;20181204&quot;</span></span><br><span class="line">CMD [<span class="string">&quot;/bin/bash&quot;</span>]</span><br></pre></td></tr></table></figure>
<p>Docker Hub 中 99% 的镜像都是从<code>FROM scratch</code> 开始的。</p>
<blockquote>
<p>规则</p>
</blockquote>
<ul>
<li>每个指令都必须是大写字母。</li>
<li>按照从上到下顺序执行。</li>
<li><strong>#</strong> 表示注释。</li>
<li>每一条指令都会创建一个新的镜像层。</li>
</ul>
<blockquote>
<p>解释</p>
</blockquote>
<ul>
<li><code>FROM</code>：基础镜像，比如 centos。</li>
<li><code>MAINTAINER</code>：镜像是谁写的。建议以此格式：<code>姓名&lt;邮箱&gt;</code>。</li>
<li><code>RUN</code>：镜像构建时需要运行的命令。</li>
<li><code>ADD</code>：添加，比如添加一个 tomcat 压缩包。</li>
<li><code>WORKDIR</code>：镜像的工作目录。</li>
<li><code>VOLUME</code>：挂载的目录。</li>
<li><code>EXPOSE</code>：指定暴露端口，跟 -p 一个道理。</li>
<li><code>RUN</code>：最终要运行的。</li>
<li><code>CMD</code>：指定这个容器启动的时候要运行的命令，只有最后一个会生效，而且可被替代。</li>
<li><code>ENTRYPOINT</code>：指定这个容器启动的时候要运行的命令，可以追加命令。</li>
<li><code>ONBUILD</code>：当构建一个被继承Dockerfile 这个时候运行ONBUILD指定，触发指令。</li>
<li><code>COPY</code>：将文件拷贝到镜像中。</li>
<li><code>ENV</code>：构建的时候设置环境变量。</li>
</ul>
<h2 id="构建镜像"><a class="markdownIt-Anchor" href="#构建镜像"></a> 构建镜像</h2>
<h3 id="docker-build"><a class="markdownIt-Anchor" href="#docker-build"></a> docker build</h3>
<p>Dockerfile 编写好后，需要使用 <code>docker build</code> 命令运行。</p>
<blockquote>
<p>语法</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build [参数] 路径 | 网络地址 | -</span><br></pre></td></tr></table></figure>
<blockquote>
<p>参数</p>
</blockquote>
<ul>
<li><code>-f</code>：指定要使用的Dockerfile路径。</li>
<li><code>-t</code>：镜像的名字及标签，通常 <strong>name:tag</strong> 或者 <strong>name</strong> 格式；可以在一次构建中为一个镜像设置多个标签。</li>
<li><code>-m</code>：设置内存最大值。</li>
</ul>
<blockquote>
<p>Docker 守护进程执行 Dockerfile 中的指令前，首先会对 Dockerfile 进行语法检查，有语法错误时会返回报错信息。</p>
</blockquote>
<h2 id="查看构建记录"><a class="markdownIt-Anchor" href="#查看构建记录"></a> 查看构建记录</h2>
<h3 id="docker-history"><a class="markdownIt-Anchor" href="#docker-history"></a> docker history</h3>
<blockquote>
<p>语法</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker <span class="built_in">history</span> 镜像</span><br></pre></td></tr></table></figure>
<h2 id="cmd-与-entrypoint-区别"><a class="markdownIt-Anchor" href="#cmd-与-entrypoint-区别"></a> CMD 与 ENTRYPOINT 区别</h2>
<h3 id="cmd-命令演示"><a class="markdownIt-Anchor" href="#cmd-命令演示"></a> CMD 命令演示</h3>
<blockquote>
<p>编写 Dockerfile</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># vim Dockerfile-cmd-test</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># cat Dockerfile-cmd-test </span></span><br><span class="line">FROM centos</span><br><span class="line">CMD [<span class="string">&quot;ls&quot;</span>,<span class="string">&quot;-a&quot;</span>]</span><br></pre></td></tr></table></figure>
<blockquote>
<p>构建镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker build -f Dockerfile-cmd-test -t zmtest .</span></span><br><span class="line">Sending build context to Docker daemon  <span class="number">2.048</span>kB</span><br><span class="line">Step <span class="number">1</span>/<span class="number">2</span> : FROM centos</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">5</span>d0da3dc9764</span><br><span class="line">Step <span class="number">2</span>/<span class="number">2</span> : CMD [<span class="string">&quot;ls&quot;</span>,<span class="string">&quot;-a&quot;</span>]</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">0</span>a743e929fff</span><br><span class="line">Removing intermediate container <span class="number">0</span>a743e929fff</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">1683</span>c0790d49</span><br><span class="line">Successfully built <span class="number">1683</span>c0790d49</span><br><span class="line">Successfully tagged zmtest:latest</span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY        TAG       IMAGE ID       CREATED          SIZE</span><br><span class="line">zmtest           latest    <span class="number">1683</span>c0790d49   <span class="number">13</span> minutes ago   <span class="number">231</span>MB</span><br></pre></td></tr></table></figure>
<blockquote>
<p>运行镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker run zmtest</span></span><br><span class="line">.</span><br><span class="line">..</span><br><span class="line">.dockerenv</span><br><span class="line">bin</span><br><span class="line">dev</span><br><span class="line">etc</span><br><span class="line">home</span><br><span class="line">lib</span><br><span class="line">lib64</span><br><span class="line">lost+found</span><br><span class="line">media</span><br><span class="line">mnt</span><br><span class="line">opt</span><br><span class="line">proc</span><br><span class="line">root</span><br><span class="line">run</span><br><span class="line">sbin</span><br><span class="line">srv</span><br><span class="line">sys</span><br><span class="line">tmp</span><br><span class="line">usr</span><br><span class="line">var</span><br></pre></td></tr></table></figure>
<p>此时 Dockerfile 中编写的命令生效了。</p>
<blockquote>
<p>追加 -l 命令</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker run zmtest -l</span></span><br><span class="line">docker: Error response from daemon: OCI runtime create failed: container_linux.go:<span class="number">380</span>: starting container <span class="keyword">process</span> caused: exec: <span class="string">&quot;-l&quot;</span>: executable file not found <span class="keyword">in</span> <span class="variable">$PATH:</span> unknown.</span><br><span class="line">ERRO[<span class="number">0000</span>] error waiting <span class="keyword">for</span> container: context canceled</span><br></pre></td></tr></table></figure>
<p>没有达到预期的 <code>ls -al</code> 命令。</p>
<blockquote>
<p>CMD 是替换的方式， -l 不是命令，所以报错。</p>
</blockquote>
<h3 id="entrypoint-命令演示"><a class="markdownIt-Anchor" href="#entrypoint-命令演示"></a> ENTRYPOINT 命令演示</h3>
<blockquote>
<p>编写 Dockerfile</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># vim Dockerfile-ent-test</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># cat Dockerfile-ent-test </span></span><br><span class="line">FROM centos</span><br><span class="line">ENTRYPOINT [<span class="string">&quot;ls&quot;</span>,<span class="string">&quot;-a&quot;</span>]</span><br></pre></td></tr></table></figure>
<blockquote>
<p>构建镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker build -f Dockerfile-ent-test -t ent-test .</span></span><br><span class="line">Sending build context to Docker daemon  <span class="number">3.072</span>kB</span><br><span class="line">Step <span class="number">1</span>/<span class="number">2</span> : FROM centos</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">5</span>d0da3dc9764</span><br><span class="line">Step <span class="number">2</span>/<span class="number">2</span> : ENTRYPOINT [<span class="string">&quot;ls&quot;</span>,<span class="string">&quot;-a&quot;</span>]</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> a02d55ae0a00</span><br><span class="line">Removing intermediate container a02d55ae0a00</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">795973</span>a0ed43</span><br><span class="line">Successfully built <span class="number">795973</span>a0ed43</span><br><span class="line">Successfully tagged ent<span class="literal">-test</span>:latest</span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY        TAG       IMAGE ID       CREATED          SIZE</span><br><span class="line">ent<span class="literal">-test</span>   latest    <span class="number">795973</span>a0ed43   <span class="number">22</span> seconds ago   <span class="number">231</span>MB</span><br></pre></td></tr></table></figure>
<blockquote>
<p>运行镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker run ent-test</span></span><br><span class="line">.</span><br><span class="line">..</span><br><span class="line">.dockerenv</span><br><span class="line">bin</span><br><span class="line">dev</span><br><span class="line">etc</span><br><span class="line">home</span><br><span class="line">lib</span><br><span class="line">lib64</span><br><span class="line">lost+found</span><br><span class="line">media</span><br><span class="line">mnt</span><br><span class="line">opt</span><br><span class="line">proc</span><br><span class="line">root</span><br><span class="line">run</span><br><span class="line">sbin</span><br><span class="line">srv</span><br><span class="line">sys</span><br><span class="line">tmp</span><br><span class="line">usr</span><br><span class="line">var</span><br></pre></td></tr></table></figure>
<p>此时 Dockerfile 中编写的命令也生效了。</p>
<blockquote>
<p>追加 -l 命令</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker run ent-test -l</span></span><br><span class="line">total <span class="number">56</span></span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">1</span> root root <span class="number">4096</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> .</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">1</span> root root <span class="number">4096</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> ..</span><br><span class="line"><span class="literal">-rwxr-xr-x</span>   <span class="number">1</span> root root    <span class="number">0</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> .dockerenv</span><br><span class="line">lrwxrwxrwx   <span class="number">1</span> root root    <span class="number">7</span> Nov  <span class="number">3</span>  <span class="number">2020</span> bin -&gt; usr/bin</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">5</span> root root  <span class="number">340</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> dev</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">1</span> root root <span class="number">4096</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> etc</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">2</span> root root <span class="number">4096</span> Nov  <span class="number">3</span>  <span class="number">2020</span> home</span><br><span class="line">lrwxrwxrwx   <span class="number">1</span> root root    <span class="number">7</span> Nov  <span class="number">3</span>  <span class="number">2020</span> lib -&gt; usr/lib</span><br><span class="line">lrwxrwxrwx   <span class="number">1</span> root root    <span class="number">9</span> Nov  <span class="number">3</span>  <span class="number">2020</span> lib64 -&gt; usr/lib64</span><br><span class="line">drwx<span class="literal">------</span>   <span class="number">2</span> root root <span class="number">4096</span> Sep <span class="number">15</span>  <span class="number">2021</span> lost+found</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">2</span> root root <span class="number">4096</span> Nov  <span class="number">3</span>  <span class="number">2020</span> media</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">2</span> root root <span class="number">4096</span> Nov  <span class="number">3</span>  <span class="number">2020</span> mnt</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">2</span> root root <span class="number">4096</span> Nov  <span class="number">3</span>  <span class="number">2020</span> opt</span><br><span class="line">dr<span class="literal">-xr-xr-x</span> <span class="number">352</span> root root    <span class="number">0</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> proc</span><br><span class="line">dr<span class="literal">-xr-x---</span>   <span class="number">2</span> root root <span class="number">4096</span> Sep <span class="number">15</span>  <span class="number">2021</span> root</span><br><span class="line">drwxr<span class="literal">-xr-x</span>  <span class="number">11</span> root root <span class="number">4096</span> Sep <span class="number">15</span>  <span class="number">2021</span> run</span><br><span class="line">lrwxrwxrwx   <span class="number">1</span> root root    <span class="number">8</span> Nov  <span class="number">3</span>  <span class="number">2020</span> sbin -&gt; usr/sbin</span><br><span class="line">drwxr<span class="literal">-xr-x</span>   <span class="number">2</span> root root <span class="number">4096</span> Nov  <span class="number">3</span>  <span class="number">2020</span> srv</span><br><span class="line">dr<span class="literal">-xr-xr-x</span>  <span class="number">11</span> root root    <span class="number">0</span> Mar <span class="number">27</span> <span class="number">10</span>:<span class="number">26</span> sys</span><br><span class="line">drwxrwxrwt   <span class="number">7</span> root root <span class="number">4096</span> Sep <span class="number">15</span>  <span class="number">2021</span> tmp</span><br><span class="line">drwxr<span class="literal">-xr-x</span>  <span class="number">12</span> root root <span class="number">4096</span> Sep <span class="number">15</span>  <span class="number">2021</span> usr</span><br><span class="line">drwxr<span class="literal">-xr-x</span>  <span class="number">20</span> root root <span class="number">4096</span> Sep <span class="number">15</span>  <span class="number">2021</span> var</span><br></pre></td></tr></table></figure>
<p>运行了预期的 <code>ls -al</code> 命令。</p>
<blockquote>
<p>ENTRYPOINT 是追加的方式。</p>
</blockquote>
<p>Docker 中许多命令都十分相似，我们需要了解他们的区别，最好的方式就是这样对比测试。</p>
<h2 id="实战"><a class="markdownIt-Anchor" href="#实战"></a> 实战</h2>
<h3 id="创建包含vim命令的centos镜像"><a class="markdownIt-Anchor" href="#创建包含vim命令的centos镜像"></a> 创建包含vim命令的centos镜像</h3>
<blockquote>
<p>编写 Dockerfile</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># vim Dockerfile-centos-my </span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># cat Dockerfile-centos-my </span></span><br><span class="line">FROM centos</span><br><span class="line">MAINTAINER fantasy&lt;xxxxx@<span class="number">163</span>.com&gt;</span><br><span class="line">ENV MYPATH /usr/local</span><br><span class="line">WORKDIR <span class="variable">$MYPATH</span></span><br><span class="line">RUN yum <span class="literal">-y</span> install vim</span><br><span class="line">RUN yum <span class="literal">-y</span> install net<span class="literal">-tools</span></span><br><span class="line">EXPOSE <span class="number">81</span></span><br><span class="line">CMD <span class="built_in">echo</span> <span class="variable">$MYPATH</span></span><br><span class="line">CMD <span class="built_in">echo</span> <span class="string">&quot;---end---&quot;</span></span><br><span class="line">CMD [<span class="string">&quot;/bin/bash&quot;</span>]</span><br></pre></td></tr></table></figure>
<blockquote>
<p>构建镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker build -f Dockerfile-centos-my -t centos-my .</span></span><br><span class="line">Sending build context to Docker daemon  <span class="number">5.632</span>kB</span><br><span class="line">Step <span class="number">1</span>/<span class="number">10</span> : FROM centos</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">5</span>d0da3dc9764</span><br><span class="line">Step <span class="number">2</span>/<span class="number">10</span> : MAINTAINER fantasy&lt;xxxxxx@<span class="number">163</span>.com&gt;</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">8</span>b7340768878</span><br><span class="line">Removing intermediate container <span class="number">8</span>b7340768878</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">9616888</span>f3b10</span><br><span class="line">Step <span class="number">3</span>/<span class="number">10</span> : ENV MYPATH /usr/local</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">2</span>c73446a56ff</span><br><span class="line">Removing intermediate container <span class="number">2</span>c73446a56ff</span><br><span class="line"> <span class="literal">---</span>&gt; be89377d4c2c</span><br><span class="line">Step <span class="number">4</span>/<span class="number">10</span> : WORKDIR <span class="variable">$MYPATH</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> db113c4f7cb2</span><br><span class="line">Removing intermediate container db113c4f7cb2</span><br><span class="line"> <span class="literal">---</span>&gt; fb41ece5d944</span><br><span class="line">Step <span class="number">5</span>/<span class="number">10</span> : RUN yum <span class="literal">-y</span> install vim</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> eccee60c0389</span><br><span class="line">CentOS Linux <span class="number">8</span> - AppStream                       <span class="number">12</span> MB/s | <span class="number">8.4</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">CentOS Linux <span class="number">8</span> - BaseOS                         <span class="number">1.7</span> MB/s | <span class="number">3.6</span> MB     <span class="number">00</span>:<span class="number">02</span>    </span><br><span class="line">CentOS Linux <span class="number">8</span> - Extras                          <span class="number">17</span> kB/s |  <span class="number">10</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">Last metadata expiration check: <span class="number">0</span>:<span class="number">00</span>:<span class="number">01</span> ago on Sat Dec <span class="number">25</span> <span class="number">05</span>:<span class="number">09</span>:<span class="number">40</span> <span class="number">2021</span>.</span><br><span class="line">Dependencies resolved.</span><br><span class="line">================================================================================</span><br><span class="line"> Package             Arch        Version                   Repository      Size</span><br><span class="line">================================================================================</span><br><span class="line">Installing:</span><br><span class="line"> vim<span class="literal">-enhanced</span>        x86_64      <span class="number">2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8         appstream      <span class="number">1.4</span> M</span><br><span class="line">Installing dependencies:</span><br><span class="line"> gpm<span class="literal">-libs</span>            x86_64      <span class="number">1.20</span>.<span class="number">7</span><span class="literal">-17</span>.el8             appstream       <span class="number">39</span> k</span><br><span class="line"> vim<span class="literal">-common</span>          x86_64      <span class="number">2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8         appstream      <span class="number">6.3</span> M</span><br><span class="line"> vim<span class="literal">-filesystem</span>      noarch      <span class="number">2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8         appstream       <span class="number">49</span> k</span><br><span class="line"> which               x86_64      <span class="number">2.21</span><span class="literal">-16</span>.el8               baseos          <span class="number">49</span> k</span><br><span class="line">Transaction Summary</span><br><span class="line">================================================================================</span><br><span class="line">Install  <span class="number">5</span> Packages</span><br><span class="line">Total download size: <span class="number">7.8</span> M</span><br><span class="line">Installed size: <span class="number">30</span> M</span><br><span class="line">Downloading Packages:</span><br><span class="line">(<span class="number">1</span>/<span class="number">5</span>): gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64.rpm        <span class="number">582</span> kB/s |  <span class="number">39</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">2</span>/<span class="number">5</span>): vim<span class="literal">-filesystem-8</span>.<span class="number">0.1763</span><span class="literal">-16</span>.el8.noarch.rp <span class="number">1.2</span> MB/s |  <span class="number">49</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">3</span>/<span class="number">5</span>): vim<span class="literal">-common-8</span>.<span class="number">0.1763</span><span class="literal">-16</span>.el8.x86_64.rpm     <span class="number">40</span> MB/s | <span class="number">6.3</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">4</span>/<span class="number">5</span>): vim<span class="literal">-enhanced-8</span>.<span class="number">0.1763</span><span class="literal">-16</span>.el8.x86_64.rpm  <span class="number">7.1</span> MB/s | <span class="number">1.4</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">5</span>/<span class="number">5</span>): which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64.rpm             <span class="number">252</span> kB/s |  <span class="number">49</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line"><span class="literal">--------------------------------------------------------------------------------</span></span><br><span class="line">Total                                           <span class="number">6.4</span> MB/s | <span class="number">7.8</span> MB     <span class="number">00</span>:<span class="number">01</span>     </span><br><span class="line">warning: /var/cache/dnf/appstream<span class="literal">-02e86d1c976ab532</span>/packages/gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID <span class="number">8483</span>c65d: NOKEY</span><br><span class="line">CentOS Linux <span class="number">8</span> - AppStream                      <span class="number">1.6</span> MB/s | <span class="number">1.6</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">Importing GPG key <span class="number">0</span>x8483C65D:</span><br><span class="line"> Userid     : <span class="string">&quot;CentOS (CentOS Official Signing Key) &lt;security@centos.org&gt;&quot;</span></span><br><span class="line"> Fingerprint: <span class="number">99</span>DB <span class="number">70</span>FA E1D7 CE22 <span class="number">7</span>FB6 <span class="number">4882</span> <span class="number">05</span>B5 <span class="number">55</span>B3 <span class="number">8483</span> C65D</span><br><span class="line"> From       : /etc/pki/rpm<span class="literal">-gpg</span>/RPM<span class="literal">-GPG-KEY-centosofficial</span></span><br><span class="line">Key imported successfully</span><br><span class="line">Running transaction check</span><br><span class="line">Transaction check succeeded.</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded.</span><br><span class="line">Running transaction</span><br><span class="line">  Preparing        :                                                        <span class="number">1</span>/<span class="number">1</span> </span><br><span class="line">  Installing       : which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64                               <span class="number">1</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : vim<span class="literal">-filesystem-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.noarch                <span class="number">2</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                    <span class="number">3</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64                          <span class="number">4</span>/<span class="number">5</span> </span><br><span class="line">  Running scriptlet: gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64                          <span class="number">4</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                  <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">  Running scriptlet: vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                  <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">  Running scriptlet: vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                    <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64                          <span class="number">1</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                    <span class="number">2</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                  <span class="number">3</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : vim<span class="literal">-filesystem-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.noarch                <span class="number">4</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64                               <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">Installed:</span><br><span class="line">  gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64         vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64    </span><br><span class="line">  vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64 vim<span class="literal">-filesystem-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.noarch</span><br><span class="line">  which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64             </span><br><span class="line">Complete!</span><br><span class="line">Removing intermediate container eccee60c0389</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">9</span>f54f48660<span class="built_in">ac</span></span><br><span class="line">Step <span class="number">6</span>/<span class="number">10</span> : RUN yum <span class="literal">-y</span> install net<span class="literal">-tools</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">6</span>caa7361b001</span><br><span class="line">Last metadata expiration check: <span class="number">0</span>:<span class="number">00</span>:<span class="number">08</span> ago on Sat Dec <span class="number">25</span> <span class="number">05</span>:<span class="number">09</span>:<span class="number">40</span> <span class="number">2021</span>.</span><br><span class="line">Dependencies resolved.</span><br><span class="line">================================================================================</span><br><span class="line"> Package         Architecture Version                        Repository    Size</span><br><span class="line">================================================================================</span><br><span class="line">Installing:</span><br><span class="line"> net<span class="literal">-tools</span>       x86_64       <span class="number">2.0</span><span class="literal">-0</span>.<span class="number">52.20160912</span>git.el8       baseos       <span class="number">322</span> k</span><br><span class="line">Transaction Summary</span><br><span class="line">================================================================================</span><br><span class="line">Install  <span class="number">1</span> Package</span><br><span class="line">Total download size: <span class="number">322</span> k</span><br><span class="line">Installed size: <span class="number">942</span> k</span><br><span class="line">Downloading Packages:</span><br><span class="line">net<span class="literal">-tools-2</span>.<span class="number">0</span><span class="literal">-0</span>.<span class="number">52.20160912</span>git.el8.x86_64.rpm   <span class="number">1.0</span> MB/s | <span class="number">322</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line"><span class="literal">--------------------------------------------------------------------------------</span></span><br><span class="line">Total                                           <span class="number">449</span> kB/s | <span class="number">322</span> kB     <span class="number">00</span>:<span class="number">00</span>     </span><br><span class="line">Running transaction check</span><br><span class="line">Transaction check succeeded.</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded.</span><br><span class="line">Running transaction</span><br><span class="line">  Preparing        :                                                        <span class="number">1</span>/<span class="number">1</span> </span><br><span class="line">  Installing       : net<span class="literal">-tools-2</span>.<span class="number">0</span><span class="literal">-0</span>.<span class="number">52.20160912</span>git.el8.x86_64              <span class="number">1</span>/<span class="number">1</span> </span><br><span class="line">  Running scriptlet: net<span class="literal">-tools-2</span>.<span class="number">0</span><span class="literal">-0</span>.<span class="number">52.20160912</span>git.el8.x86_64              <span class="number">1</span>/<span class="number">1</span> </span><br><span class="line">  Verifying        : net<span class="literal">-tools-2</span>.<span class="number">0</span><span class="literal">-0</span>.<span class="number">52.20160912</span>git.el8.x86_64              <span class="number">1</span>/<span class="number">1</span> </span><br><span class="line">Installed:</span><br><span class="line">  net<span class="literal">-tools-2</span>.<span class="number">0</span><span class="literal">-0</span>.<span class="number">52.20160912</span>git.el8.x86_64                                     </span><br><span class="line">Complete!</span><br><span class="line">Removing intermediate container <span class="number">6</span>caa7361b001</span><br><span class="line"> <span class="literal">---</span>&gt; a9431f90fd3f</span><br><span class="line">Step <span class="number">7</span>/<span class="number">10</span> : EXPOSE <span class="number">81</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> ad67fa23940a</span><br><span class="line">Removing intermediate container ad67fa23940a</span><br><span class="line"> <span class="literal">---</span>&gt; b5bd21416741</span><br><span class="line">Step <span class="number">8</span>/<span class="number">10</span> : CMD <span class="built_in">echo</span> <span class="variable">$MYPATH</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> fb1d08538689</span><br><span class="line">Removing intermediate container fb1d08538689</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">5</span>c5def0bbb85</span><br><span class="line">Step <span class="number">9</span>/<span class="number">10</span> : CMD <span class="built_in">echo</span> <span class="string">&quot;---end---&quot;</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> a9d955b6b389</span><br><span class="line">Removing intermediate container a9d955b6b389</span><br><span class="line"> <span class="literal">---</span>&gt; ad95558eb658</span><br><span class="line">Step <span class="number">10</span>/<span class="number">10</span> : CMD [<span class="string">&quot;/bin/bash&quot;</span>]</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">190651202</span>e7b</span><br><span class="line">Removing intermediate container <span class="number">190651202</span>e7b</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">7</span>d202bdf002b</span><br><span class="line">Successfully built <span class="number">7</span>d202bdf002b</span><br><span class="line">Successfully tagged centos<span class="literal">-my</span>:latest</span><br></pre></td></tr></table></figure>
<blockquote>
<p>查看构建的镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY        TAG       IMAGE ID       CREATED              SIZE</span><br><span class="line">centos<span class="literal">-my</span>       latest    <span class="number">7</span>d202bdf002b   About a minute ago   <span class="number">323</span>MB</span><br></pre></td></tr></table></figure>
<blockquote>
<p>查看本地镜像的构建记录</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">dockerfile</span>]<span class="comment"># docker history centos-my</span></span><br><span class="line">IMAGE          CREATED         CREATED BY                                      SIZE      COMMENT</span><br><span class="line"><span class="number">7</span>d202bdf002b   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  CMD [&quot;/bin/bash&quot;]            0B        </span></span><br><span class="line">ad95558eb658   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo…   0B        </span></span><br><span class="line"><span class="number">5</span>c5def0bbb85   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo…   0B        </span></span><br><span class="line">b5bd21416741   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  EXPOSE 81                    0B        </span></span><br><span class="line">a9431f90fd3f   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> yum <span class="literal">-y</span> install net<span class="literal">-tools</span>             <span class="number">27.3</span>MB    </span><br><span class="line"><span class="number">9</span>f54f48660<span class="built_in">ac</span>   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> yum <span class="literal">-y</span> install vim                   <span class="number">64.8</span>MB    </span><br><span class="line">fb41ece5d944   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop) WORKDIR /usr/local            0B        </span></span><br><span class="line">be89377d4c2c   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  ENV MYPATH=/usr/local        0B        </span></span><br><span class="line"><span class="number">9616888</span>f3b10   <span class="number">5</span> minutes ago   /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  MAINTAINER fantasy&lt;yifanfantasy…   0B        </span></span><br><span class="line"><span class="number">5</span>d0da3dc9764   <span class="number">3</span> months ago    /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  CMD [&quot;/bin/bash&quot;]            0B        </span></span><br><span class="line">&lt;missing&gt;      <span class="number">3</span> months ago    /bin/sh <span class="literal">-c</span> <span class="comment">#(nop)  LABEL org.label-schema.sc…   0B        </span></span><br><span class="line">&lt;missing&gt;      <span class="number">3</span> months ago    /bin/sh <span class="literal">-c</span> <span class="comment">#(nop) ADD file:805cb5e15fb6e0bb0…   231MB</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>运行测试</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> ~]<span class="comment"># docker run -it centos-my</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">530551</span><span class="type">bc2162</span> <span class="type">local</span>]<span class="comment"># pwd</span></span><br><span class="line">/usr/local</span><br><span class="line">[<span class="type">root</span>@<span class="number">530551</span><span class="type">bc2162</span> <span class="type">local</span>]<span class="comment"># vim test.java</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">530551</span><span class="type">bc2162</span> <span class="type">local</span>]<span class="comment">#</span></span><br></pre></td></tr></table></figure>
<p>默认的工作目录正是 Dockerfile 中设置的 <code>/usr/local</code> ，且可以使用 <code>vim</code> 命令了。</p>
<h3 id="自定义tomcat环境镜像"><a class="markdownIt-Anchor" href="#自定义tomcat环境镜像"></a> 自定义tomcat环境镜像</h3>
<blockquote>
<p>编写 Dockerfile</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">FROM centos</span><br><span class="line">MAINTAINER fantasy&lt;xxxxxx@<span class="number">163</span>.com&gt;</span><br><span class="line"><span class="built_in">COPY</span> readme.txt /usr/local/readme.txt</span><br><span class="line">ENV MYPATH /usr/local/</span><br><span class="line">WORKDIR <span class="variable">$MYPATH</span></span><br><span class="line">ADD jdk<span class="literal">-8u301-linux-x64</span>.tar.gz <span class="variable">$MYPATH</span></span><br><span class="line">ADD apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span>.tar.gz <span class="variable">$MYPATH</span></span><br><span class="line">RUN yum <span class="literal">-y</span> install vim</span><br><span class="line">ENV JAVA_HOME <span class="variable">$MYPATH</span>/jdk1.<span class="number">8.0</span>_301<span class="literal">-amd64</span></span><br><span class="line">ENV CLASSPATH <span class="variable">$JAVA_HOME</span>/lib/</span><br><span class="line">ENV CATALINA_HOME <span class="variable">$MYPATH</span>/apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span></span><br><span class="line">ENV CATALINA_BASH <span class="variable">$MYPATH</span>/apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span></span><br><span class="line">ENV PATH <span class="variable">$PATH:</span><span class="variable">$JAVA_HOME</span>/bin:<span class="variable">$CATALINA_HOME</span>/bin:<span class="variable">$CATALINA_HOME</span>/lib</span><br><span class="line">EXPOSE <span class="number">8080</span></span><br><span class="line">CMD <span class="variable">$CATALINA_HOME</span>/bin/startup.sh &amp;&amp; tail <span class="operator">-F</span> <span class="variable">$CATALINA_HOME</span>/logs/catalina.out</span><br></pre></td></tr></table></figure>
<p>其中的 <strong>readme.txt</strong> 一般作为镜像说明文件，可以在里面编写镜像的信息。</p>
<blockquote>
<p>构建镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># docker build -t tomcat-test .</span></span><br><span class="line">Sending build context to Docker daemon  <span class="number">157.1</span>MB</span><br><span class="line">Step <span class="number">1</span>/<span class="number">15</span> : FROM centos</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">5</span>d0da3dc9764</span><br><span class="line">Step <span class="number">2</span>/<span class="number">15</span> : MAINTAINER fantasy&lt;xxxxxx@<span class="number">163</span>.com&gt;</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="keyword">Using</span> cache</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">9616888</span>f3b10</span><br><span class="line">Step <span class="number">3</span>/<span class="number">15</span> : <span class="built_in">COPY</span> readme.txt /usr/local/readme.txt</span><br><span class="line"> <span class="literal">---</span>&gt; da792df641f8</span><br><span class="line">Step <span class="number">4</span>/<span class="number">15</span> : ENV MYPATH /usr/local/</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> e4a5b13decd7</span><br><span class="line">Removing intermediate container e4a5b13decd7</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">7</span>b1e6970b4b3</span><br><span class="line">Step <span class="number">5</span>/<span class="number">15</span> : WORKDIR <span class="variable">$MYPATH</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">835</span>dabd080dd</span><br><span class="line">Removing intermediate container <span class="number">835</span>dabd080dd</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">7</span>be17b1556ee</span><br><span class="line">Step <span class="number">6</span>/<span class="number">15</span> : ADD jdk<span class="literal">-8u301-linux-x64</span>.tar.gz <span class="variable">$MYPATH</span></span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">480721043</span>fda</span><br><span class="line">Step <span class="number">7</span>/<span class="number">15</span> : ADD apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span>.tar.gz <span class="variable">$MYPATH</span></span><br><span class="line"> <span class="literal">---</span>&gt; c7bfa13bfcd1</span><br><span class="line">Step <span class="number">8</span>/<span class="number">15</span> : RUN yum <span class="literal">-y</span> install vim</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">85532523</span>d784</span><br><span class="line">CentOS Linux <span class="number">8</span> - AppStream                      <span class="number">9.0</span> MB/s | <span class="number">8.4</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">CentOS Linux <span class="number">8</span> - BaseOS                         <span class="number">5.6</span> MB/s | <span class="number">3.6</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">CentOS Linux <span class="number">8</span> - Extras                          <span class="number">20</span> kB/s |  <span class="number">10</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">Dependencies resolved.</span><br><span class="line">================================================================================</span><br><span class="line"> Package             Arch        Version                   Repository      Size</span><br><span class="line">================================================================================</span><br><span class="line">Installing:</span><br><span class="line"> vim<span class="literal">-enhanced</span>        x86_64      <span class="number">2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8         appstream      <span class="number">1.4</span> M</span><br><span class="line">Installing dependencies:</span><br><span class="line"> gpm<span class="literal">-libs</span>            x86_64      <span class="number">1.20</span>.<span class="number">7</span><span class="literal">-17</span>.el8             appstream       <span class="number">39</span> k</span><br><span class="line"> vim<span class="literal">-common</span>          x86_64      <span class="number">2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8         appstream      <span class="number">6.3</span> M</span><br><span class="line"> vim<span class="literal">-filesystem</span>      noarch      <span class="number">2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8         appstream       <span class="number">49</span> k</span><br><span class="line"> which               x86_64      <span class="number">2.21</span><span class="literal">-16</span>.el8               baseos          <span class="number">49</span> k</span><br><span class="line">Transaction Summary</span><br><span class="line">================================================================================</span><br><span class="line">Install  <span class="number">5</span> Packages</span><br><span class="line">Total download size: <span class="number">7.8</span> M</span><br><span class="line">Installed size: <span class="number">30</span> M</span><br><span class="line">Downloading Packages:</span><br><span class="line">(<span class="number">1</span>/<span class="number">5</span>): gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64.rpm        <span class="number">973</span> kB/s |  <span class="number">39</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">2</span>/<span class="number">5</span>): vim<span class="literal">-filesystem-8</span>.<span class="number">0.1763</span><span class="literal">-16</span>.el8.noarch.rp <span class="number">726</span> kB/s |  <span class="number">49</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">3</span>/<span class="number">5</span>): vim<span class="literal">-enhanced-8</span>.<span class="number">0.1763</span><span class="literal">-16</span>.el8.x86_64.rpm   <span class="number">10</span> MB/s | <span class="number">1.4</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">4</span>/<span class="number">5</span>): which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64.rpm             <span class="number">901</span> kB/s |  <span class="number">49</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">(<span class="number">5</span>/<span class="number">5</span>): vim<span class="literal">-common-8</span>.<span class="number">0.1763</span><span class="literal">-16</span>.el8.x86_64.rpm     <span class="number">27</span> MB/s | <span class="number">6.3</span> MB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line"><span class="literal">--------------------------------------------------------------------------------</span></span><br><span class="line">Total                                           <span class="number">6.6</span> MB/s | <span class="number">7.8</span> MB     <span class="number">00</span>:<span class="number">01</span>     </span><br><span class="line">warning: /var/cache/dnf/appstream<span class="literal">-02e86d1c976ab532</span>/packages/gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID <span class="number">8483</span>c65d: NOKEY</span><br><span class="line">CentOS Linux <span class="number">8</span> - AppStream                      <span class="number">1.6</span> MB/s | <span class="number">1.6</span> kB     <span class="number">00</span>:<span class="number">00</span>    </span><br><span class="line">Importing GPG key <span class="number">0</span>x8483C65D:</span><br><span class="line"> Userid     : <span class="string">&quot;CentOS (CentOS Official Signing Key) &lt;security@centos.org&gt;&quot;</span></span><br><span class="line"> Fingerprint: <span class="number">99</span>DB <span class="number">70</span>FA E1D7 CE22 <span class="number">7</span>FB6 <span class="number">4882</span> <span class="number">05</span>B5 <span class="number">55</span>B3 <span class="number">8483</span> C65D</span><br><span class="line"> From       : /etc/pki/rpm<span class="literal">-gpg</span>/RPM<span class="literal">-GPG-KEY-centosofficial</span></span><br><span class="line">Key imported successfully</span><br><span class="line">Running transaction check</span><br><span class="line">Transaction check succeeded.</span><br><span class="line">Running transaction test</span><br><span class="line">Transaction test succeeded.</span><br><span class="line">Running transaction</span><br><span class="line">  Preparing        :                                                        <span class="number">1</span>/<span class="number">1</span> </span><br><span class="line">  Installing       : which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64                               <span class="number">1</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : vim<span class="literal">-filesystem-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.noarch                <span class="number">2</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                    <span class="number">3</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64                          <span class="number">4</span>/<span class="number">5</span> </span><br><span class="line">  Running scriptlet: gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64                          <span class="number">4</span>/<span class="number">5</span> </span><br><span class="line">  Installing       : vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                  <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">  Running scriptlet: vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                  <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">  Running scriptlet: vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                    <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64                          <span class="number">1</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                    <span class="number">2</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64                  <span class="number">3</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : vim<span class="literal">-filesystem-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.noarch                <span class="number">4</span>/<span class="number">5</span> </span><br><span class="line">  Verifying        : which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64                               <span class="number">5</span>/<span class="number">5</span> </span><br><span class="line">Installed:</span><br><span class="line">  gpm<span class="literal">-libs-1</span>.<span class="number">20.7</span><span class="literal">-17</span>.el8.x86_64         vim<span class="literal">-common-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64    </span><br><span class="line">  vim<span class="literal">-enhanced-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.x86_64 vim<span class="literal">-filesystem-2</span>:<span class="number">8.0</span>.<span class="number">1763</span><span class="literal">-16</span>.el8.noarch</span><br><span class="line">  which<span class="literal">-2</span>.<span class="number">21</span><span class="literal">-16</span>.el8.x86_64             </span><br><span class="line">Complete!</span><br><span class="line">Removing intermediate container <span class="number">85532523</span>d784</span><br><span class="line"> <span class="literal">---</span>&gt; e091ece0364d</span><br><span class="line">Step <span class="number">9</span>/<span class="number">15</span> : ENV JAVA_HOME <span class="variable">$MYPATH</span>/jdk1.<span class="number">8.0</span>_301<span class="literal">-amd64</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">473066</span>cf57f4</span><br><span class="line">Removing intermediate container <span class="number">473066</span>cf57f4</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">0</span>a8963a2c1ab</span><br><span class="line">Step <span class="number">10</span>/<span class="number">15</span> : ENV CLASSPATH <span class="variable">$JAVA_HOME</span>/lib/</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">78</span>a2cb9b06<span class="built_in">cd</span></span><br><span class="line">Removing intermediate container <span class="number">78</span>a2cb9b06<span class="built_in">cd</span></span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">3</span>dd34a2857b4</span><br><span class="line">Step <span class="number">11</span>/<span class="number">15</span> : ENV CATALINA_HOME <span class="variable">$MYPATH</span>/apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">4</span>ca540479e3d</span><br><span class="line">Removing intermediate container <span class="number">4</span>ca540479e3d</span><br><span class="line"> <span class="literal">---</span>&gt; fa38f4581510</span><br><span class="line">Step <span class="number">12</span>/<span class="number">15</span> : ENV CATALINA_BASH <span class="variable">$MYPATH</span>/apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">31</span>dc5b38478c</span><br><span class="line">Removing intermediate container <span class="number">31</span>dc5b38478c</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">8</span>ae919106bf6</span><br><span class="line">Step <span class="number">13</span>/<span class="number">15</span> : ENV PATH <span class="variable">$PATH:</span><span class="variable">$JAVA_HOME</span>/bin:<span class="variable">$CATALINA_HOME</span>/bin:<span class="variable">$CATALINA_HOME</span>/lib</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> d3fe1f81fab7</span><br><span class="line">Removing intermediate container d3fe1f81fab7</span><br><span class="line"> <span class="literal">---</span>&gt; dd8b07b2adfd</span><br><span class="line">Step <span class="number">14</span>/<span class="number">15</span> : EXPOSE <span class="number">8080</span></span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">1</span>f1601f2dcc2</span><br><span class="line">Removing intermediate container <span class="number">1</span>f1601f2dcc2</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">9078648</span>b7a2e</span><br><span class="line">Step <span class="number">15</span>/<span class="number">15</span> : CMD <span class="variable">$CATALINA_HOME</span>/bin/startup.sh &amp;&amp; tail <span class="operator">-F</span> <span class="variable">$CATALINA_HOME</span>/logs/catalina.out</span><br><span class="line"> <span class="literal">---</span>&gt; Running <span class="keyword">in</span> <span class="number">6</span>a3b2aefaf44</span><br><span class="line">Removing intermediate container <span class="number">6</span>a3b2aefaf44</span><br><span class="line"> <span class="literal">---</span>&gt; <span class="number">23</span>a538c107a0</span><br><span class="line">Successfully built <span class="number">23</span>a538c107a0</span><br><span class="line">Successfully tagged tomcat<span class="literal">-test</span>:latest</span><br></pre></td></tr></table></figure>
<blockquote>
<p>查看镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY        TAG       IMAGE ID       CREATED          SIZE</span><br><span class="line">tomcat<span class="literal">-test</span>       latest    <span class="number">23</span>a538c107a0   <span class="number">25</span> minutes ago   <span class="number">673</span>MB</span><br></pre></td></tr></table></figure>
<blockquote>
<p>启动镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># docker run -d -p 8080:8080 --name fantasy-tomcat -v /home/fantasy/tomcat/webinfos:/usr/local/apache-tomcat-9.0.55/webinfos -v /home/fantasy/tomcat/logs:/usr/local/apache-tomcat-9.0.55/logs tomcat-test </span></span><br><span class="line"><span class="number">9</span>d391e13efdc495206429dbdb0392180a7bd3a4750cbc1419c31c80cd69c6b7b</span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment">#</span></span><br></pre></td></tr></table></figure>
<p>启动时将 tomcat 的 <strong>webinfos</strong> 和 <strong>logs</strong> 目录都挂载到了本机。</p>
<blockquote>
<p>查看挂载目录</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># ls /home/fantasy/tomcat</span></span><br><span class="line">logs  webinfos</span><br></pre></td></tr></table></figure>
<p>这里找到了挂载到本机的两个目录，说明挂载成功了。</p>
<blockquote>
<p>进入容器</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># docker ps</span></span><br><span class="line">CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS          PORTS                    NAMES</span><br><span class="line"><span class="number">9</span>d391e13efdc   tomcat<span class="literal">-test</span>   <span class="string">&quot;/bin/sh -c &#x27;<span class="variable">$CATALI</span>…&quot;</span>   <span class="number">24</span> minutes ago   Up <span class="number">24</span> minutes   <span class="number">0.0</span>.<span class="number">0.0</span>:<span class="number">8080</span>-&gt;<span class="number">8080</span>/tcp   fantasy<span class="literal">-tomcat</span></span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># docker exec -it 9d391e13efdc /bin/bash</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">9</span><span class="type">d391e13efdc</span> <span class="type">local</span>]<span class="comment"># ls</span></span><br><span class="line">apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span>  bin  etc    games  include    jdk1.<span class="number">8.0</span>_301  lib  lib64  libexec  readme.txt  sbin  share  src</span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># docker exec -it 9d391e13efdc /bin/bash</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">9</span><span class="type">d391e13efdc</span> <span class="type">local</span>]<span class="comment"># ls</span></span><br><span class="line">apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span>  bin  etc    games  include    jdk1.<span class="number">8.0</span>_301  lib  lib64  libexec  readme.txt  sbin  share  src</span><br></pre></td></tr></table></figure>
<p>jdk 和 readme.txt 都是具备了的，且 tomcat 目录下的文件也是完整的。</p>
<blockquote>
<p>查看挂载文件</p>
</blockquote>
<p>这里以 logs 为例，我们先进入 tomcat 容器中的 logs 文件夹查看日志内容。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="number">9</span><span class="type">d391e13efdc</span> <span class="type">apache</span>-<span class="type">tomcat</span>-<span class="number">9.0</span><span class="type">.55</span>]<span class="comment"># cd logs</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">9</span><span class="type">d391e13efdc</span> <span class="type">logs</span>]<span class="comment"># ls</span></span><br><span class="line">catalina.out</span><br><span class="line">[<span class="type">root</span>@<span class="number">9</span><span class="type">d391e13efdc</span> <span class="type">logs</span>]<span class="comment"># cat catalina.out </span></span><br><span class="line">/usr/local//apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span>/bin/catalina.sh: line <span class="number">504</span>: /usr/local//jdk1.<span class="number">8.0</span>_301<span class="literal">-amd64</span>/bin/java: No such file or directory</span><br></pre></td></tr></table></figure>
<p>然后再退出查看主机上挂载的 logs 文件夹。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="number">9</span><span class="type">d391e13efdc</span> <span class="type">logs</span>]<span class="comment"># exit</span></span><br><span class="line"><span class="keyword">exit</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">tomcat</span>]<span class="comment"># cd /home/fantasy/tomcat/logs</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># ls</span></span><br><span class="line">catalina.out</span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># cat catalina.out </span></span><br><span class="line">/usr/local//apache<span class="literal">-tomcat-9</span>.<span class="number">0.55</span>/bin/catalina.sh: line <span class="number">504</span>: /usr/local//jdk1.<span class="number">8.0</span>_301<span class="literal">-amd64</span>/bin/java: No such file or directory</span><br></pre></td></tr></table></figure>
<p>两个地方 logs 下的文件内容一致，说明挂载成功。</p>
<h2 id="发布镜像到-docker-hub"><a class="markdownIt-Anchor" href="#发布镜像到-docker-hub"></a> 发布镜像到 Docker Hub</h2>
<blockquote>
<p>注册账号</p>
</blockquote>
<p>如果没有 Docker Hub 账号，先注册账号：<span class="exturl" data-url="aHR0cHM6Ly9odWIuZG9ja2VyLmNvbS8=">https://hub.docker.com/<i class="fa fa-external-link-alt"></i></span></p>
<blockquote>
<p>登录 Docker Hub 账号</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker login -u fantasyke</span></span><br><span class="line">Password: </span><br><span class="line">WARNING! Your password will be stored unencrypted <span class="keyword">in</span> /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/<span class="comment">#credentials-store</span></span><br><span class="line">Login Succeeded</span><br></pre></td></tr></table></figure>
<h3 id="发布镜像"><a class="markdownIt-Anchor" href="#发布镜像"></a> 发布镜像</h3>
<h3 id="docker-push"><a class="markdownIt-Anchor" href="#docker-push"></a> docker push</h3>
<blockquote>
<p>直接发布镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker push centos-myUsing default tag: latestThe push refers to repository [docker.io/library/centos-my]de70c523870b: </span></span><br><span class="line">Preparing <span class="number">909</span>db45c4bc4: </span><br><span class="line">Preparing <span class="number">74</span>ddd0ec08fa: </span><br><span class="line">Preparing denied: requested access to the resource is denied</span><br></pre></td></tr></table></figure>
<p>访问资源被拒绝了。拒绝的原因是我们没有带标签，默认的 latest 标签是不能被识别的。</p>
<h3 id="指定镜像标签"><a class="markdownIt-Anchor" href="#指定镜像标签"></a> 指定镜像标签</h3>
<h3 id="docker-tag"><a class="markdownIt-Anchor" href="#docker-tag"></a> docker tag</h3>
<p>我们可以使用 <code>docker tag</code> 命令给镜像加一个标签。</p>
<blockquote>
<p>必须以 账号名/镜像名:标签 的格式命令才能提交。</p>
</blockquote>
<p>找到之前打的测试镜像 <code>centos-my</code> IMAGE ID</p>
<blockquote>
<p>再次发布镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker tag 7d202bdf002b fantasyke/centos:1.0</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY        TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">fantasyke/centos   <span class="number">1.0</span>       <span class="number">7</span>d202bdf002b   <span class="number">29</span> hours ago   <span class="number">323</span>MB</span><br><span class="line">centos<span class="literal">-my</span>       latest    <span class="number">7</span>d202bdf002b   <span class="number">29</span> hours ago   <span class="number">323</span>MB</span><br></pre></td></tr></table></figure>
<p>这样就能发布成功了。且可以发现，<strong>镜像的发布也是分层发布的</strong>。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker push fantasyke/centos:1.0</span></span><br><span class="line"><span class="keyword">Using</span> default tag: latest</span><br><span class="line">The push refers to repository [<span class="type">docker.io</span>/<span class="type">library</span>/<span class="type">centos</span>-<span class="type">my</span>]</span><br><span class="line">The push refers to repository [<span class="type">docker.io</span>/<span class="type">fantasyke</span>/<span class="type">centos</span>]</span><br><span class="line"><span class="number">74</span>ddd0ec08fa: Mounted from library/centos</span><br><span class="line"><span class="number">1.0</span>: digest: sha256:<span class="number">58</span>c60ae4f5f1e27d7027ebc641f60f6768a474b617a30b48916fe02de14e0892 size: <span class="number">529</span></span><br></pre></td></tr></table></figure>
<p>这样就发布成功了。</p>
<h2 id="配置国内镜像站"><a class="markdownIt-Anchor" href="#配置国内镜像站"></a> 配置国内镜像站</h2>
<p>由于对国外网络的限制，发布镜像到 DockerHub 是比较缓慢的。</p>
<p>这里可以使用配置 <strong>Docker 国内镜像站</strong>的方式实现加速。</p>
<p>运行以下命令即可：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> ~]<span class="comment"># curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s XXXXXXX</span></span><br><span class="line">docker version &gt;= <span class="number">1.12</span></span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;registry-mirrors&quot;</span>: [<span class="string">&quot;XXXXXXXXX&quot;</span>]</span><br><span class="line">&#125;</span><br><span class="line">Success.</span><br><span class="line">You need to restart docker to take effect: sudo systemctl restart docker</span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> ~]<span class="comment"># systemctl restart docker</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> ~]<span class="comment">#</span></span><br></pre></td></tr></table></figure>
<p>该脚本可以将 <code>--registry-mirror</code> 加入到 Docker 配置文件 <code>/etc/docker/daemon.json</code> 中。</p>
<p>适用于 <strong>Ubuntu14.04</strong>、<strong>Debian</strong>、<strong>CentOS6</strong> 、<strong>CentOS7</strong>、<strong>Fedora</strong>、<strong>Arch Linux</strong>、<strong>openSUSE Leap 42.1</strong>，其他版本可能有细微不同。</p>
<blockquote>
<p>去 Docker Hub 上以 账号名/镜像名 搜索我们刚发布的镜像，发现是可以搜索到的。</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.58he6tnxat.webp" alt="image.png" /></p>
<blockquote>
<p>查看详情也可以镜像的具体信息。</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.6pnj8kse8h.webp" alt="image.png" /></p>
<p>DIGEST 的值正是刚才发布后返回值 <code>ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</code> 的缩写。</p>
<p>且镜像的大小是小于我们本地镜像的，说明<strong>发布的过程中也会压缩镜像</strong>。</p>
<blockquote>
<p>拉取我们发布的镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker pull fantasyke/centos:1.0</span></span><br><span class="line"><span class="number">1.0</span>: Pulling from fantasyke/centos</span><br><span class="line">Digest: sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</span><br><span class="line">Status: Image is up to date <span class="keyword">for</span> fantasyke/centos:<span class="number">1.0</span></span><br><span class="line">docker.io/fantasyke/centos:<span class="number">1.0</span></span><br></pre></td></tr></table></figure>
<p>无法拉取。原因很简单，因为我们本地存在了同名镜像。</p>
<blockquote>
<p>我们先删除这个镜像再拉取</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker rmi -f 7d202bdf002b</span></span><br><span class="line">Untagged: fantasyke/centos:<span class="number">1.0</span></span><br><span class="line">Untagged: fantasyke/centos@sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</span><br><span class="line">Untagged: centos<span class="literal">-my</span>:latest</span><br><span class="line">Untagged: fantasy/centos:<span class="number">1.0</span></span><br><span class="line">Deleted: sha256:<span class="number">7</span>d202bdf002bbd95d8016fa5807a486d6c50e195879eddd88cb602172fc51ffe</span><br><span class="line">Deleted: sha256:ad95558eb65801f5871215837558156c5e33ba351b3b52e0a50aac045abb46c1</span><br><span class="line">Deleted: sha256:<span class="number">5</span>c5def0bbb85d8779d02f115c3d072fe9adb1fd07556ee8c5a130823ecf6811d</span><br><span class="line">Deleted: sha256:b5bd21416741daec348f417dbea1b73001e257f1e63a5d2abddabc8554fca611</span><br><span class="line">Deleted: sha256:a9431f90fd3f23387c456ad5b925dbb9531beece3eab825848db99db29c6a1fa</span><br><span class="line">Deleted: sha256:<span class="number">9</span>f54f48660acb350921aefab74769e51fc7917a1e1e730d3df2edd1513517c42</span><br><span class="line">Deleted: sha256:fb41ece5d944c667762945fdf7275a1d267acd92fe9dc56709fc3adaca6f087f</span><br><span class="line">Deleted: sha256:be89377d4c2ccea11308d8196ba53f03985882db015e01ed8b54fc114f4ba058</span><br><span class="line">Deleted: sha256:<span class="number">9616888</span>f3b103230ed5f378af4afc11b7ce7ed3d96653e5bd918c49152bbdf8c</span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker pull fantasyke/centos:1.0</span></span><br><span class="line"><span class="number">1.0</span>: Pulling from fantasyke/centos</span><br><span class="line">a1d0c7532777: Already exists </span><br><span class="line"><span class="number">0594</span>d57f8468: Already exists </span><br><span class="line"><span class="number">9</span>c13f720f33e: Already exists </span><br><span class="line">Digest: sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</span><br><span class="line">Status: Downloaded newer image <span class="keyword">for</span> fantasyke/centos:<span class="number">1.0</span></span><br><span class="line">docker.io/fantasyke/centos:<span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY        TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">fantasyke/centos   <span class="number">1.0</span>       <span class="number">7</span>d202bdf002b   <span class="number">29</span> hours ago   <span class="number">323</span>MB</span><br></pre></td></tr></table></figure>
<p>拉取成功，且大小又恢复到了之前本地的镜像大小，说明<strong>拉取的过程中也会解压镜像</strong>。</p>
<blockquote>
<p>启动拉取的镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker run -it fantasyke/centos:1.0 /bin/bash</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">168</span><span class="type">c9e550886</span> <span class="type">local</span>]<span class="comment"># vim test.java</span></span><br><span class="line">[<span class="type">root</span>@<span class="number">168</span><span class="type">c9e550886</span> <span class="type">local</span>]<span class="comment">#</span></span><br></pre></td></tr></table></figure>
<p><code>vim</code> 命令也是可以使用的，镜像发布成功。</p>
<h2 id="发布镜像到阿里云镜像仓库"><a class="markdownIt-Anchor" href="#发布镜像到阿里云镜像仓库"></a> 发布镜像到阿里云镜像仓库</h2>
<blockquote>
<p>登录阿里云，点击我的阿里云</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.2a543bg8jo.webp" alt="image.png" /></p>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.4n7qkiudta.webp" alt="image.png" /></p>
<blockquote>
<p>创建实例</p>
</blockquote>
<p>这里以创建个人版实例为例。</p>
<p>我这里已经创建好了，如果没有创建点击创建即可。</p>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1e8mnv72b7.webp" alt="image.png" /></p>
<blockquote>
<p>进入镜像仓库</p>
</blockquote>
<p>创建好个人实例后，点击进入。</p>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1026wzyzzk.webp" alt="image.png" /></p>
<blockquote>
<p>创建命名空间</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.4ckwrdfs71.webp" alt="image.png" /></p>
<p>一个账号只能创建 3 个命名空间，需要谨慎创建。</p>
<p>创建好后就是这样。</p>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.361lirri0b.webp" alt="image.png" /></p>
<blockquote>
<p>创建镜像仓库</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1hs8ll1dsv.webp" alt="image.png" /></p>
<blockquote>
<p>点击下一步，创建本地仓库</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.1hs8ll1lhc.webp" alt="image.png" /></p>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.2a543big37.webp" alt="image.png" /></p>
<p>至此，我们就创建好了阿里云的镜像仓库，具体的操作步骤上图也写得非常清楚。</p>
<blockquote>
<p>退出登录的账号</p>
</blockquote>
<p>如果之前登录了 Docker Hub 账号或者其他阿里云账号，先退出账号。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker logout</span></span><br><span class="line">Removing login credentials <span class="keyword">for</span> https://index.docker.io/v1/</span><br></pre></td></tr></table></figure>
<blockquote>
<p>登录阿里云账号</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker login --username=******** registry.cn-hangzhou.aliyuncs.com</span></span><br><span class="line">Password: </span><br><span class="line">WARNING! Your password will be stored unencrypted <span class="keyword">in</span> /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/<span class="comment">#credentials-store</span></span><br><span class="line">Login Succeeded</span><br></pre></td></tr></table></figure>
<blockquote>
<p>设置镜像标签</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker tag 7d202bdf002b registry.cn-hangzhou.aliyuncs.com/fantasyke/fantasy:1.0</span></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY                                        TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">fantasyke/centos                                   <span class="number">1.0</span>       <span class="number">7</span>d202bdf002b   <span class="number">32</span> hours ago   <span class="number">323</span>MB</span><br><span class="line">registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy   <span class="number">1.0</span>       <span class="number">7</span>d202bdf002b   <span class="number">32</span> hours ago   <span class="number">323</span>MB</span><br></pre></td></tr></table></figure>
<blockquote>
<p>提交镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker push registry.cn-hangzhou.aliyuncs.com/fantasyke/fantasy:1.0</span></span><br><span class="line">The push refers to repository [<span class="type">registry.cn</span>-<span class="type">hangzhou.aliyuncs.com</span>/<span class="type">fantasyke</span>/<span class="type">fantasy</span>]</span><br><span class="line">de70c523870b: Pushed </span><br><span class="line"><span class="number">909</span>db45c4bc4: Pushed </span><br><span class="line"><span class="number">74</span>ddd0ec08fa: Pushed </span><br><span class="line"><span class="number">1.0</span>: digest: sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1 size: <span class="number">953</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>查看提交的镜像</p>
</blockquote>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.45phjre6c.webp" alt="image.png" /></p>
<p>提交的镜像可以在这里查看。</p>
<blockquote>
<p>拉取镜像</p>
</blockquote>
<p>先删除本地镜像， 再拉取测试。</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker rmi -f 7d202bdf002b</span></span><br><span class="line">Untagged: fantasyke/centos:<span class="number">1.0</span></span><br><span class="line">Untagged: fantasyke/centos@sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</span><br><span class="line">Untagged: registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy/centos:<span class="number">1.0</span></span><br><span class="line">Untagged: registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy:<span class="number">1.0</span></span><br><span class="line">Untagged: registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy@sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</span><br><span class="line">Deleted: sha256:<span class="number">7</span>d202bdf002bbd95d8016fa5807a486d6c50e195879eddd88cb602172fc51ffe</span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker pull registry.cn-hangzhou.aliyuncs.com/fantasyke/fantasy:1.0</span></span><br><span class="line"><span class="number">1.0</span>: Pulling from fantasyke/fantasy</span><br><span class="line">a1d0c7532777: Already exists </span><br><span class="line"><span class="number">0594</span>d57f8468: Already exists </span><br><span class="line"><span class="number">9</span>c13f720f33e: Already exists </span><br><span class="line">Digest: sha256:ecefaae6c5a2cab84693175ea3b18d0d0a7aa0160e33a0bf3eb4ab626b10f0f1</span><br><span class="line">Status: Downloaded newer image <span class="keyword">for</span> registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy:<span class="number">1.0</span></span><br><span class="line">registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy:<span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker images</span></span><br><span class="line">REPOSITORY                                        TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">registry.cn<span class="literal">-hangzhou</span>.aliyuncs.com/fantasyke/fantasy   <span class="number">1.0</span>       <span class="number">7</span>d202bdf002b   <span class="number">32</span> hours ago   <span class="number">323</span>MB</span><br></pre></td></tr></table></figure>
<blockquote>
<p>启动镜像</p>
</blockquote>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="type">root</span>@<span class="type">fantasy</span> <span class="type">logs</span>]<span class="comment"># docker run -it registry.cn-hangzhou.aliyuncs.com/fantasyke/fantasy:1.0</span></span><br></pre></td></tr></table></figure>
<p><img src="https://fantasy-ke.github.io/picx-images-hosting/docker/image.9kg7edawsp.webp" alt="image.png" /></p>

    </div>

    
    
    

    <footer class="post-footer">







<div class="license">
  <div class="license-title">5.Dockerfile</div>
  <div class="license-link">
    <a href="https://blog.fantasyke.cn/posts/11767/">https://blog.fantasyke.cn/posts/11767/</a>
  </div>
  <div class="license-meta">
    <div class="license-meta-item">
      <div class="license-meta-title">本文作者</div>
      <div class="license-meta-text">
          Fantasy-ke
      </div>
    </div>
      <div class="license-meta-item">
        <div class="license-meta-title">发布于</div>
        <div class="license-meta-text">
          2023-04-11
        </div>
      </div>
      <div class="license-meta-item">
        <div class="license-meta-title">更新于</div>
        <div class="license-meta-text">
          2024-12-17
        </div>
      </div>
    <div class="license-meta-item">
      <div class="license-meta-title">许可协议</div>
      <div class="license-meta-text">
          禁止转载引用
      </div>
    </div>
  </div>
  <div class="license-statement">
      如需转载或引用本文，请先获得作者授权！
  </div>
</div>
          <div class="reward-container">
  <div>Buy me a coffee</div>
  <button>
    Donate
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.png" alt="Fantasy-ke WeChat Pay">
        <span>WeChat Pay</span>
      </div>

  </div>
</div>

          <div class="followme">
  <span>Welcome to my other publishing channels</span>

  <div class="social-list">

      <div class="social-item">
          <a target="_blank" class="social-link" href="https://github.com/fantasy-ke">
            <span class="icon">
              <i class="fab fa-github"></i>
            </span>

            <span class="label">GitHub</span>
          </a>
      </div>
  </div>
</div>

          <div class="post-tags">
              <a href="/tags/Docker/" rel="tag"><i class="fa fa-tag"></i> Docker</a>
          </div>

        
  <div class="social-like a2a_kit a2a_kit_size_32 a2a_default_style">
    <a class="a2a_dd" target="_blank" rel="noopener" href="https://www.addtoany.com/share"></a>
      <a class="a2a_button_facebook"></a>
      <a class="a2a_button_twitter"></a>
      <a class="a2a_button_telegram"></a>
      <a class="a2a_button_wechat"></a>
  </div>

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/posts/12360/" rel="prev" title="6.Docker网络">
                  <i class="fa fa-angle-left"></i> 6.Docker网络
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/posts/23547/" rel="next" title="4.Docker镜像原理">
                  4.Docker镜像原理 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments gitalk-container"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2021 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-solid fa-t-rex"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Fantasy-ke</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>Word count total: </span>
    <span title="Word count total">72k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>Reading time total &asymp;</span>
    <span title="Reading time total">4:21</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div> 
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment-precise-range-plugin@1.3.0/moment-precise-range.min.js"></script>
<script>
  var now = new Date();
  function timer() {
    var grt= new Date("03/12/2022 13:14:21");//此处修改你的建站时间或者网站上线时间
    now.setTime(now.getTime()+250);
    days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
    hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
    if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
    seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
    var ages = `${dnum}天${hnum}小时${mnum}分${snum}秒`;
    div.innerHTML = `本站已安全运行 ${ages} 🐶`;
  }
  var div = document.createElement("div");
  //插入到copyright之后
  var copyright = document.querySelector(".busuanzi-count");
  document.querySelector(".footer-inner").insertBefore(div, copyright.nextSibling);
  timer();
  setInterval("timer()",1000)
</script>


<div class="footer-menu">
    <a style="color: chocolate;" href="/tags/">文章标签</a> · <a style="color: chocolate;"  href="/policy/">网站政策</a> · <a style="color: chocolate;"  href="/photos/">文章相册</a>
</div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2ZhbnRhc3kta2U=" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.31/fancybox/fancybox.umd.js" integrity="sha256-a+H7FYzJv6oU2hfsfDGM2Ohw/cR9v+hPfxHCLdmCrE8=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/sidebar.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>


  <script src="/js/third-party/addtoany.js"></script>

  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




<script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>

<script>
var options = {
  bottom: '64px',
  right: 'unset',
  left: '32px',
  time: '0.5s',
  mixColor: 'transparent',
  backgroundColor: 'transparent',
  buttonColorDark: '#100f2c',
  buttonColorLight: '#fff',
  saveInCookies: true,
  label: '🌓',
  autoMatchOsTheme: true
}
const darkmode = new Darkmode(options);
window.darkmode = darkmode;
darkmode.showWidget();
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/gitalk/1.8.0/gitalk.css" integrity="sha256-AJnUHL7dBv6PGaeyPQJcgQPDjt/Hn/PvYZde1iqfp8U=" crossorigin="anonymous">

<script class="next-config" data-name="gitalk" type="application/json">{"enable":true,"github_id":"fantasy-ke","repo":"fantasy-ke.github.io","client_id":"Ov23li8eCFrhnzfiGx5T","client_secret":"ce23581c2059392ebd00afd08d5ba43f767fd1b1","admin_user":"fantasy-ke","distraction_free_mode":true,"proxy":"https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token","language":"zh-CN","labels":"gitalk","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/gitalk/1.8.0/gitalk.min.js","integrity":"sha256-MVK9MGD/XJaGyIghSVrONSnoXoGh3IFxLw0zfvzpxR4="},"path_md5":"f983030e472b3b925295f89bb8a23431"}</script>
<script src="/js/third-party/comments/gitalk.js"></script>


<script src="/js/minigrid.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script data-pjax type="text/javascript">
var album = document.querySelector(".album");
if (album) {
  // 相册列表 JSON 数据
  var imgDataPath = album.getAttribute('json-src');
  // 照片存储路径
  var imgPath = album.getAttribute('photo-src');
  // 最多显示数量
  var imgMaxNum = 50;
  // 获取窗口大小以决定图片宽度
  var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  var imageWidth;

  if (windowWidth < 768) {
    imageWidth = 145; // 移动端图片宽度
  } else {
    imageWidth = 235;
  }

  // 生成相册
  var linkDataPath = imgDataPath;
  var photo = {
    page: 1,
    offset: imgMaxNum,
    init: function () {
      var that = this;
      $.getJSON(linkDataPath, function (data) {
          that.render(that.page, data);
      });
    },
    render: function (page, data) {
      var begin = (page - 1) * this.offset;
      var end = page * this.offset;
      if (begin >= data.length) return;
      var imgNameWithPattern, imgName, imageSize, imageX, imageY, li = "";
      for (var i = begin; i < end && i < data.length; i++) {
        imgNameWithPattern = data[i].path;
        imgName = data[i].name;
        imageSize = data[i].size;
        li += '<div class="card" style="width:' + imageWidth + 'px" >';
        li += '<div class="album-photo" style="height:' + imageWidth + 'px" >';
        li += '<a class="fancybox fancybox.image" href="' + imgPath + imgNameWithPattern + '" itemscope="" itemtype="http://schema.org/ImageObject" itemprop="url" data-fancybox="group" rel="group" data-caption="' + imgName + '" title="' +  imgName + '">';
        li += '<img data-src="' + imgPath + imgNameWithPattern + '" src="' + imgPath + imgNameWithPattern + '" alt="' +  imgName + '" data-loaded="true">';
        li += '</a>';
        li += '</div>';
        li += '</div>';
      }
      album.insertAdjacentHTML('beforeend', li);
      this.minigrid();
    },
    minigrid: function () {
      var grid = new Minigrid({
        container: '.album',
        item: '.card',
        gutter: 12
      });
      grid.mount();
      window.addEventListener('resize', function () {
        grid.mount();
      });
    }
  };
  photo.init();
}
</script>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"model":{"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":170,"height":330},"mobile":{"show":true},"react":{"opacity":0.7},"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
